package com.fantastic.service.zjs.impl;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.exception.sql.DeleteException;
import com.fantastic.common.exception.sql.InsertException;
import com.fantastic.common.exception.sql.SelectException;
import com.fantastic.common.exception.sql.UpdateException;
import com.fantastic.common.utils.IsEmptyUtils;
import com.fantastic.mapper.zjs.MemberVarietyMapper;
import com.fantastic.model.pojo.zjs.MemberVariety;
import com.fantastic.service.zjs.MemberVarietyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/4 16:23
 * @description: 会员卡和菜品关联表service接口实现类
 */
@Service
public class MemberVarietyServiceImpl implements MemberVarietyService {

    @Resource
    private MemberVarietyMapper memberVarietyMapper;

    /**
     * 查询会员卡和菜品关联信息
     *
     * @param memberVariety
     * @return
     */
    @Override
    public List<MemberVariety> listMemberVariety(MemberVariety memberVariety) {
        List<MemberVariety> memberVarieties = memberVarietyMapper.listMemberVariety(memberVariety);
        IsEmptyUtils.listIsEmpty(new SelectException(RespStatusInfo.SELECT_NULL), memberVarieties);
        return memberVarieties;
    }

    /**
     * 查询单个会员卡和菜品关联信息
     *
     * @param memberId
     * @param varietyId
     * @return
     */
    @Override
    public MemberVariety getMemberVariety(Integer memberId, Integer varietyId) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.DATA_ERROR), memberId, varietyId);
        return memberVarietyMapper.getMemberVariety(memberId, varietyId);
    }

    /**
     * 添加会员卡和菜品关联信息
     *
     * @param memberVariety
     * @return
     */
    @Override
    public Integer insertMemberVariety(MemberVariety memberVariety) {
        IsEmptyUtils.integerIsEmpty(new InsertException(RespStatusInfo.DATA_ERROR),
                memberVariety.getMemberId(),
                memberVariety.getVarietyId());
        IsEmptyUtils.objectIsNull(new InsertException(RespStatusInfo.DATA_ERROR), memberVariety.getMemberVarietyPrice());
        return memberVarietyMapper.insertMemberVariety(memberVariety);
    }

    /**
     * 修改会员卡和菜品关联信息
     *
     * @param memberVariety
     * @return
     */
    @Override
    public Integer updateMemberVariety(MemberVariety memberVariety) {
        IsEmptyUtils.integerIsEmpty(new UpdateException(RespStatusInfo.DATA_ERROR),
                memberVariety.getMemberId(),
                memberVariety.getVarietyId());
        IsEmptyUtils.objectIsNull(new UpdateException(RespStatusInfo.DATA_ERROR), memberVariety.getMemberVarietyPrice());
        return memberVarietyMapper.updateMemberVariety(memberVariety);
    }

    /**
     * 删除会员卡和菜品关联信息
     *
     * @param memberId
     * @param varietyId
     * @return
     */
    @Override
    public Integer deleteMemberVariety(Integer memberId, Integer varietyId) {
        IsEmptyUtils.integerIsEmpty(new DeleteException(RespStatusInfo.DATA_ERROR), memberId, varietyId);
        return memberVarietyMapper.deleteMemberVariety(memberId, varietyId);
    }


}
